package com.wh.testCAS;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

//ABA问题
public class CASDemo1 {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(2021);
        //======================捣乱的线程=====================
        System.out.println(atomicInteger.compareAndSet(2021, 2022));
        System.out.println(atomicInteger.get());

        System.out.println(atomicInteger.compareAndSet(2022, 2021));
        System.out.println(atomicInteger.get());
        //======================捣乱的线程=====================

        //======================期望的线程=====================
        System.out.println(atomicInteger.compareAndSet(2021, 666));
        System.out.println(atomicInteger.get());


    }
}
